package com.xhs.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 统一响应DTO
 *
 * @author xhs
 */
@Data
@Schema(description = "统一响应格式")
public class XhsResponse<T> {

    /**
     * 响应码
     */
    @Schema(description = "响应码", example = "200")
    private Integer code;

    /**
     * 响应消息
     */
    @Schema(description = "响应消息", example = "操作成功")
    private String message;

    /**
     * 响应数据
     */
    @Schema(description = "响应数据")
    private T data;

    /**
     * 响应时间戳
     */
    @Schema(description = "响应时间戳", example = "1703123456789")
    private Long timestamp;

    public XhsResponse() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> XhsResponse<T> success(T data) {
        XhsResponse<T> response = new XhsResponse<>();
        response.setCode(200);
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static <T> XhsResponse<T> success(String message, T data) {
        XhsResponse<T> response = new XhsResponse<>();
        response.setCode(200);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    public static <T> XhsResponse<T> error(String message) {
        XhsResponse<T> response = new XhsResponse<>();
        response.setCode(500);
        response.setMessage(message);
        return response;
    }

    public static <T> XhsResponse<T> error(Integer code, String message) {
        XhsResponse<T> response = new XhsResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
} 